package com.wayne.leetcode.problems;

import java.util.HashMap;
import java.util.Map;

public class Solution2404 {
  public static int mostFrequentEven(int[] nums) {
    HashMap<Integer, Integer> counter = new HashMap<>();
    for (int x : nums) {
      if (x % 2 == 0) {
        counter.put(x, counter.getOrDefault(x, 0) + 1);
      }
    }
    // res 值 ct 最大出现次数
    int res = -1, ct = 0;
    for (Map.Entry<Integer, Integer> entry : counter.entrySet()) {
      if (res == -1 || entry.getValue() > ct || entry.getValue() == ct && res > entry.getKey()){
        res = entry.getKey();
        ct = entry.getValue();
      }
    }
    return res;
  }

  public static void main(String[] args) {
    mostFrequentEven(new int[]{0, 1, 2, 2, 4, 4, 1});

  }
}